package com.power.using.myapplication.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.method.ScrollingMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.power.using.myapplication.R;
import com.power.using.myapplication.base.BaseBackFragment;
import com.power.using.myapplication.bean.ShowBean;
import com.zhy.http.okhttp.OkHttpUtils;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by 聪明一只哈 on 2019/1/21.
 * Time: 2019/1/21  11:57
 */
public class ShowQuestionFragment extends BaseBackFragment {

    @BindView(R.id.toolbar_title)
    TextView toolbarTitle;
    @BindView(R.id.tv_question_name)
    TextView tvQuestionName;
    @BindView(R.id.tv_question_telphone)
    TextView tvQuestionTelphone;
    @BindView(R.id.tv_question_title)
    TextView tvQuestionTitle;
    @BindView(R.id.tv_question_description)
    TextView tvQuestionDescription;
    Unbinder unbinder;
    private ShowBean showBean;

    public static ShowQuestionFragment newInstance(ShowBean showBean) {
        Bundle args = new Bundle();
        args.putSerializable("getshowbean", showBean);
        ShowQuestionFragment fragment = new ShowQuestionFragment();
        fragment.setArguments(args);
        return fragment;
    }


    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_show_question, container, false);
        unbinder = ButterKnife.bind(this, view);
        intView(view);
        return view;
    }

    private void intView(View view) {
        toolbarTitle.setText("问题展示");

        tvQuestionDescription.setMovementMethod(ScrollingMovementMethod.getInstance());

        Bundle arguments = getArguments();
        if (arguments != null) {
            showBean = (ShowBean) arguments.getSerializable("getshowbean");
        }

    }

    @Override
    public void onLazyInitView(@Nullable Bundle savedInstanceState) {
        super.onLazyInitView(savedInstanceState);
        initDate();
    }

    private void initDate() {
        if(showBean!=null){
            tvQuestionTitle.setText(showBean.getTitle());
            tvQuestionDescription.setText(showBean.getDescription());
        }


    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
        EventBus.getDefault().unregister(this);
        OkHttpUtils.getInstance().cancelTag(this);
        cancelLoadingDialog();
    }
}
